<?php 

require_once '../../includefiles.php';
require_once '../../model/users.php';

if($_SESSION['getbids_id']!='')
{
	header("Location: ".SITE_URL."/");
	exit;		
}


$errMsg='';
$userObj= new Model_Users();
//print_R($_GET);die();
if(isset($_GET['id1']) && $_GET['id1']!='')
{
	$userDetailArray = $userObj->getUserValueByEncryptedId($_GET['id1']);
	if(count($userDetailArray) > 0)
	{
		if($userDetailArray['user_status'] == '0')
		{
			$uDetailArray=array();
			$uDetailArray['user_status']=1;
			$userObj->editUserValueByMd5ofId($uDetailArray,$_GET['id1']);
		}
		else
			$errMsg= "Your account has been already activated.";
			
		if($_GET['id2']!='')
		{
			$jobsID = base64_decode($_GET['id2']); 
			
			// job detail	
			$jobdetArray = $userObj->getJobDetailsById($jobsID);
				//print_R($jobdetArray);die();			
			// trade detail
			$gettradedetail = $tradeObj->getTradeCategoryDetailsById($jobdetArray['trade_id']);	

			//jobtype detail
			$getjobdetail = $tradeObj->getTradeCategoryDetailsById($jobdetArray['jobtype_id']);
			
					// code for add user job view table
					$userJobViewArray["userid"] 	= base64_decode($_GET['id3']);					
					$userJobViewArray["jobid"] 		= $jobsID;
					$userJobViewArray["message"] 		= "Request a qoute";//stripslashes($_POST['message']);
					$userJobViewArray["date_added"] = date('Y-m-d');
					$jobviewId = $userObj->addUserViewJOBByValue($userJobViewArray);
					
					
					//get user job view detail
					$getuserjobviewdetail = $userObj->getUserViewjobDetailsByID($jobviewId);
					
					
					//tradesman detail 
					$TradesmanuserDetArray = $userObj->getUserDetailsByUserId($getuserjobviewdetail['userid']);
				
					$userjobviewArray = array();
					$userjobviewArray['status']	= 'Accept';
					$userObj->editUserViewJobValueById($userjobviewArray,$jobviewId);	
					
					$userjobArray = array();
					$userjobArray['project_status']	= 'Accept';
					$userObj->editJobPostValueByJOBId($userjobArray,$jobsID);
					
					
					// send email message to Tradesman accepted
					$email_message = $emailObj->getEmailById(13);
					$e_subject = $email_message['email_subject'];
					$message = $email_message['email_content']; 
					
					$subject = str_replace('[STATUS]', 'Accepted', $e_subject);
					$subject = str_replace('[SITENAME]', SITENAME, $subject);		 
				
					$message = str_replace('[TRADESMAN_NAME]', trim($TradesmanuserDetArray["first_name"])." ".trim($TradesmanuserDetArray["last_name"]) , $message);	
					$message = str_replace('[HOME_NAME]', trim($userDetailArray["first_name"])." ".trim($userDetailArray["last_name"]) , $message);
					$message = str_replace('[STATUS]','Accepted', $message);
					$message = str_replace('[TRADE]', trim($gettradedetail["trade_category"]), $message);
					$message = str_replace('[JOBTYPE]', trim($getjobdetail["trade_category"]), $message); 
					$message = str_replace('[JOBDESC]', trim($jobdetArray["job_desc"]), $message); 
					$message = str_replace('[SITENAME]', SITENAME, $message);
					
					
					
					$to= trim($TradesmanuserDetArray["email"]);
					$adminEmail = $adminObj->getAdminDetails();
					$from = $adminEmail;
					$fromname= SITENAME;
									 
					$emailTemplate = file_get_contents('../../emailtemplate.html');
					$template_msg = str_replace('[SITENAME]',SITENAME , $emailTemplate);
					$template_msg = str_replace('[LOGO]','<img src="'.SITE_URL.'/uploads/logo/'.$imageDetails.'">', $template_msg);
					$template_msg = str_replace('[MESSAGE]',$message,$template_msg); 
					//echo $template_msg; exit;
					if(trim($to) != '')
					@send_mail($to, $template_msg, $subject, $from, $fromname); 
				
		}	
	}
	else
	{
		 $errMsg= "Invalid key";
	}
}
else{	
	 $errMsg= "Invalid key";
}
$smarty->assign("errMsg", $errMsg);

## Unset all the objects created which are on this page
unset($userObj);

$smarty->display(TEMPLATEDIR.'/modules/signin/activation.tpl');
unset($smarty);
?>
